var gulp = require('gulp');

var less = require('gulp-less'),
    sourcemaps = require('gulp-sourcemaps'),
    postcss = require('gulp-postcss'),
    autoprefixer = require('autoprefixer'),
    cssnano = require('cssnano'),
    gulpMultiProcess = require('gulp-multi-process');

var livereload = require('gulp-livereload'),
    connect = require('gulp-connect');

gulp.task('lessTask', function () {
  var processor = [
    autoprefixer,
    cssnano
  ];
  gulp.src('less/style.less')
    .pipe(sourcemaps.init())
    .pipe(less())
    .pipe(postcss(processor))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('../public/static/css'))
    .pipe(livereload());
});

gulp.task('reload', function () {
  return gulp.src('*.html')
    .pipe(connect.reload())
});

var browserSync = require('browser-sync').create();
gulp.task('server', function () {
  // connect.server({
  //   root: '../application/index/view/index',
  //   livereload: true,
  //   port: 8080,
  //   host: '0.0.0.0'
  //   proxy:
  // });
  browserSync.init({
    proxy: "7y.local", // 指定代理url
    notify: true, // 刷新不弹出提示
  });
});

gulp.task('auto', function () {
  gulp.watch('*.html', ['reload']);
  gulp.watch('less/components/*.less', function () {
    gulpMultiProcess(['lessTask'], function () {});
  });
  gulp.watch('../public/static/css/style.css', ['reload']);
});

gulp.task('default', ['server', 'auto']);